<?php
/* @var $this yii\web\View */
/* @var $model mdm\admin\models\AuthItem */
/* @var $context mdm\admin\components\ItemController */

use mdm\admin\AnimateAsset;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\web\YiiAsset;
use yii\widgets\DetailView;
use yii\rbac\Item;

$context = $this->context;
$labels = $context->labels();
$this->title = $model->name;

$this->params['consoleactions'] = [
    [
        'label' => '<i class="ionicons ion-plus"></i> ' . Yii::t('rbac-admin', 'Create'),
        'url' => ['create'],
        'options' => ['class' => 'btn-success']
    ],
    [
        'label' => '<i class="ionicons ion-settings"></i> ' . Yii::t('rbac-admin', 'Update'),
        'url' => ['update', 'id' => $model->name],
        'options' => ['class' => 'btn-info']
    ],
    [
        'label' => '<i class="ionicons ion-close"></i> ' . Yii::t('rbac-admin', 'Delete'),
        'url' => ['delete', 'id' => $model->name],
        'options' => [
            'class' => 'red',
            'data-confirm' => Yii::t('rbac-admin', 'Are you sure to delete this item?'),
            'data-method' => 'post',
        ]
    ],
];

AnimateAsset::register($this);
YiiAsset::register($this);
$opts = Json::htmlEncode([
    'items' => $model->getItems(),
]);
$this->registerJs("var _opts = {$opts};");
$this->registerJs($this->render('_script.js'));
$animateIcon = ' <i class="glyphicon glyphicon-refresh glyphicon-refresh-animate"></i>';
?>
<div class="auth-item-view">
    <div class="row">
        <div class="col-sm-12">
            <?=
            DetailView::widget([
                'model' => $model,
                'attributes' => [
                    'name',
                    'description:ntext',
                    'ruleName',
                    [
                        'label' => '业务授权内容',
                        'attribute' => 'rawData',
                        'format' => 'raw',
                        'visible' => $model->type == Item::TYPE_ROLE
                    ],
                    [
                        'attribute' => 'data',
                        'format' => 'ntext',
                        'visible' => $model->type != Item::TYPE_ROLE
                    ],
                ],
                'template' => '<tr><th style="width:25%">{label}</th><td>{value}</td></tr>',
            ]);
            ?>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-5">
            <input class="form-control search" data-target="available" placeholder="<?= Yii::t('rbac-admin', 'Search for available'); ?>">
            <br>
            <select multiple size="20" class="form-control list" data-target="available"></select>
        </div>
        <div class="col-sm-2">
            <br><br><br>
            <?=
            Html::a('&gt;&gt;' . $animateIcon, ['assign', 'id' => $model->name], [
                'class' => 'btn btn-success btn-block btn-assign',
                'data-target' => 'available',
                'title' => Yii::t('rbac-admin', 'Assign'),
            ]);
            ?>
            <?=
            Html::a('&lt;&lt;' . $animateIcon, ['remove', 'id' => $model->name], [
                'class' => 'btn btn-danger btn-block btn-assign',
                'data-target' => 'assigned',
                'title' => Yii::t('rbac-admin', 'Remove'),
            ]);
            ?>
        </div>
        <div class="col-sm-5">
            <input class="form-control search" data-target="assigned" placeholder="<?= Yii::t('rbac-admin', 'Search for assigned'); ?>">
            <br>
            <select multiple size="20" class="form-control list" data-target="assigned"></select>
        </div>
    </div>
</div>
